import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

public class PrintClass {
	static BufferedReader bufferedReader;
	/*This variable says ho many lines must be diplayed from the file*/
	static int noOfLines = 2;

	/*This function will only take one or two lines from the document and print it*/
	/*The order of links not defined by this function*/
	public static String printSearchResults(ArrayList<String> searchResults,
			ArrayList<String> arrOfSearchTerms) {
		String search = "", str = "";

		for (int i = 0; i < searchResults.size(); i++) {
			try {
				bufferedReader = new BufferedReader(new FileReader(
						searchResults.get(i)));
				/* Get two lines of the document having that word */
				str = bufferedReader.readLine();
				while (str != null) {
					for (int j = 0; j < arrOfSearchTerms.size(); j++) {
						if (str.toLowerCase().contains(
								arrOfSearchTerms.get(j).replaceAll("\\W", ""))) {
							/* The current line that matched is appended */
							search = search + str;
							/* For loop for displaying to three lines */
							for (int k = 0; k < noOfLines; k++) {
								str = bufferedReader.readLine();
								if (str != null)
									search = search + str;
							}
							break;
						}
					}
					/* For exiting the loop */
					str = bufferedReader.readLine();
				}
				/* Closing reading the file */
				bufferedReader.close();
			} catch (Exception exception) {
			}
			/* Concatenating all the likes separated by a line */
			String line = "-------------------------------------------------------------------" +
					"-------------------------\n";
			search = search + "\n\nFilepath : " + searchResults.get(i) + "\n"
					+ line;
		}
		return search;
	}
}
